
#include "systemtray.h"
#include <QSvgRenderer>
#include <QPainter>
#include <QDebug>

SystemTray::SystemTray(QWidget *parent)
    : QWidget(parent)
    , tray_icon_(new QSystemTrayIcon(this))
{
    initUi();
    connect(tray_icon_, &QSystemTrayIcon::activated, this, &SystemTray::activated);
}

SystemTray::~SystemTray()
{

}

void SystemTray::initUi()
{
    QSvgRenderer svgRenderer(QStringLiteral(":/resources/svg/turbo.svg"));
    // 创建一个 QPixmap，大小与 SVG 默认大小匹配
    QPixmap pixmap(25, 25);
    pixmap.fill(Qt::transparent);  // 设置背景透明
    // 使用 QPainter 将 SVG 渲染到 QPixmap
    QPainter painter(&pixmap);
    svgRenderer.render(&painter);
    tray_icon_->setIcon(QIcon(pixmap));
    tray_icon_->setToolTip(tr("测试托盘"));
    tray_icon_->show();
}

void SystemTray::activated(QSystemTrayIcon::ActivationReason reason)
{
    switch (reason)
    {
        case QSystemTrayIcon::ActivationReason::Unknown:
            break;
        case QSystemTrayIcon::ActivationReason::Context:
            tray_icon_->showMessage(tr("消息"), tr("测试消息"));
            break;
        case QSystemTrayIcon::ActivationReason::DoubleClick:
            break;
        case QSystemTrayIcon::ActivationReason::Trigger:
            break;
        case QSystemTrayIcon::ActivationReason::MiddleClick:
            break;
    }
}
